//
//  RightAnswerCell.m
//  JW_BasePorject
//
//  Created by JW on 2018/7/5.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "RightAnswerCell.h"
#import "AnswerResultView.h"
@interface RightAnswerCell ()

@property (nonatomic,strong)UILabel *answerLabel;

@property (nonatomic,copy)NSAttributedString *rightStr;
@property (nonatomic,copy)NSAttributedString *userStr;
@property (nonatomic,copy)NSAttributedString *rightAttch;
@property (nonatomic,copy)NSAttributedString *errorAttch;

@property (nonatomic,strong)UILabel *contentLabel;

@property (nonatomic,strong)AnswerResultView *resultView;


@end

@implementation RightAnswerCell





- (void)addChildViews{
    [self.contentView addSubview:self.answerLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.resultView];//  150 (10+50+20+5+60+5)
    
    
}
#pragma mark - 数据处理
- (NSAttributedString *)handleRightAnswer:(NSString *)rightAnswer userAnswer:(NSString *)userAnswer{
    return self.userStr;
}


#pragma mark - property

- (AnswerResultView *)resultView{
    if (_resultView ==  nil) {
        _resultView = [[AnswerResultView alloc] initWithFrame:CGRectMake(0, 80 +5, SCREEN_WIDTH, 60)];
        
    }
    return _resultView;
}


- (UILabel *)contentLabel{
    if (_contentLabel == nil) {
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, SCREEN_WIDTH, 20)];
        _contentLabel.font = [UIFont systemFontOfSize:12];
        _contentLabel.textColor = [UIColor lightGrayColor];
    }
    return _contentLabel;
}


- (NSAttributedString *)rightStr{
    if (_rightStr == nil) {
        _rightStr = [[NSAttributedString alloc] initWithString:@"正确答案 " attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    }
    return _rightStr;
}

- (NSAttributedString *)userStr{
    if (_userStr == nil) {
        _userStr = [[NSAttributedString alloc] initWithString:@"我的答案 " attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    }
    return _userStr;
}

- (NSAttributedString *)rightAttch{
    if (_rightAttch == nil) {
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        //定义图片内容及位置和大小
        attch.image = [UIImage imageNamed:@"Paper_right"];
        attch.bounds = CGRectMake(0, 0, 50, 50);
        //创建带有图片的富文本
        _rightAttch = [NSAttributedString attributedStringWithAttachment:attch];
    }
    return _rightAttch;
}

- (NSAttributedString *)errorAttch{
    if (_errorAttch == nil) {
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        //定义图片内容及位置和大小
        attch.image = [UIImage imageNamed:@"Paper_error"];
        attch.bounds = CGRectMake(0, 0, 50, 50);
        //创建带有图片的富文本
        _errorAttch = [NSAttributedString attributedStringWithAttachment:attch];
    }
    return _errorAttch;
    
}


- (UILabel *)answerLabel{
    if (_answerLabel == nil) {
        _answerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-10- 50, 50)];
        _answerLabel.numberOfLines = 0;
    }
    return _answerLabel;
}


#pragma mark - cell

+ (RightAnswerCell *)cellWithTableView:(UITableView *)tableView{
    static NSString *ident = @"RightAnswerCell";
    
    RightAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    if (!cell) {
        cell = [[RightAnswerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addChildViews];
    }
    return  self;
}



@end
